package cn.edu.niit.server.service.impl;

import cn.edu.niit.server.domain.UserContentPraise;
import cn.edu.niit.server.repository.UserContentPraiseRepository;
import cn.edu.niit.server.service.UserContentPraiseService;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service Implementation for managing {@link UserContentPraise}.
 */
@Service
@Transactional
public class UserContentPraiseServiceImpl implements UserContentPraiseService {

    private final Logger log = LoggerFactory.getLogger(UserContentPraiseServiceImpl.class);

    private final UserContentPraiseRepository userContentPraiseRepository;

    public UserContentPraiseServiceImpl(UserContentPraiseRepository userContentPraiseRepository) {
        this.userContentPraiseRepository = userContentPraiseRepository;
    }

    @Override
    public UserContentPraise save(UserContentPraise userContentPraise) {
        log.debug("Request to save UserContentPraise : {}", userContentPraise);
        return userContentPraiseRepository.save(userContentPraise);
    }

    @Override
    public Optional<UserContentPraise> partialUpdate(UserContentPraise userContentPraise) {
        log.debug("Request to partially update UserContentPraise : {}", userContentPraise);

        return userContentPraiseRepository
            .findById(userContentPraise.getId())
            .map(
                existingUserContentPraise -> {
                    if (userContentPraise.getPraiseTime() != null) {
                        existingUserContentPraise.setPraiseTime(userContentPraise.getPraiseTime());
                    }

                    return existingUserContentPraise;
                }
            )
            .map(userContentPraiseRepository::save);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<UserContentPraise> findAll(Pageable pageable) {
        log.debug("Request to get all UserContentPraises");
        return userContentPraiseRepository.findAll(pageable);
    }

    @Override
    @Transactional(readOnly = true)
    public Optional<UserContentPraise> findOne(Long id) {
        log.debug("Request to get UserContentPraise : {}", id);
        return userContentPraiseRepository.findById(id);
    }

    @Override
    public void delete(Long id) {
        log.debug("Request to delete UserContentPraise : {}", id);
        userContentPraiseRepository.deleteById(id);
    }
}
